package com.xintoucloud.pbs.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.pbs.dao.PartyMemberPermissionDao;
import com.xintoucloud.pbs.entity.PartyMemberPermission;

@Repository@Transactional
public class PartyMemberPermissionDaoImpl implements PartyMemberPermissionDao {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<PartyMemberPermission> list() {
		return sessionFactory.getCurrentSession().createQuery("from PartyMemberPermission").list();
	}

	@Override@Transactional(readOnly=true)
	public PartyMemberPermission getOne(int ppid) {
		return  (PartyMemberPermission) sessionFactory.getCurrentSession().createQuery("from PartyMemberPermission join Menu where ppid='"+ppid+"'").getSingleResult();
	}

	@SuppressWarnings({ "unchecked", "deprecation" })
	@Override
	public List<PartyMemberPermission> listPartyMemberPermission(int pageIndex, int rows) {
		return sessionFactory.getCurrentSession().createCriteria(PartyMemberPermission.class).setFirstResult(pageIndex).setMaxResults(rows).list();
	}

	@Override
	public long count() {
		return (long) sessionFactory.getCurrentSession().createQuery("select count(*) from PartyMemberPermission").getSingleResult();
	}

	@Override
	public void addPartyMemberPermission(PartyMemberPermission partyMemberPermission) {
		sessionFactory.getCurrentSession().save(partyMemberPermission);
		
	}

	@Override
	public void deletePartyMemberPermission(int ppid) {
		sessionFactory.getCurrentSession().createQuery("delete from PartyMemberPermission where ppid=?0").setParameter(0, ppid).executeUpdate();		
	}

	@Override
	public void updatePartyMemberPermission(PartyMemberPermission partyMemberPermission) {
		sessionFactory.getCurrentSession().update(partyMemberPermission);
		
	}

}
